
		/* ...éœ¸å±äº‹ä»¶.start */
		$(".J__wchatBp").on("click", function(){
			var bpidx = wcPop({
				skin: 'ios',
				content: $("#J__popupTmpl-Baping").html(),
				style: 'background-color: #f3f3f3; max-width: 320px; width: 90%;',
				shadeClose: false,

				btns: [
					{
						text: 'æˆ‘è¦éœ¸å±',
						style: 'background:#00c1de;color:#fff;font-size:16px;',
						onTap() {
							alert("éœ¸å±æˆåŠŸï¼");
							wcPop.close(bpidx);
						}
					}
				]
			});
		});
		//éœ¸å±æ—¶é•¿picker4c9fd0901d433aa2
		$("body").on("click", ".wc__popupTmpl input[name='bpTimeline']", function(){
			var that = $(this);
			weui.picker([{
					label: '10sã€€ï¿¥8',
					value: 8
				},{
					label: '20sã€€ï¿¥16',
					value: 16
				},{
					label: '30sã€€ï¿¥24',
					value: 24
				},{
					label: '40sã€€ï¿¥32',
					value: 32
				},{
					label: '50sã€€ï¿¥40',
					value: 40
				},{
					label: '60sã€€ï¿¥48',
					value: 48
				}], {
					onChange: function(res){
						console.log(res);
					},
					onConfirm: function(res){
						console.log(res);
						that.val("ï¿¥" + res);
					}
				}
			);
		});
		/* ...éœ¸å±äº‹ä»¶.end */

		/* ...æ‰“èµäº‹ä»¶.start */
		$(".J__wchatDs").on("click", function(){
			var bpidx = wcPop({
				skin: 'ios',
				content: $("#J__popupTmpl-Dashang").html(),
				style: 'background-color: #f3f3f3; max-width: 320px; width: 90%;',
				shadeClose: false,

				btns: [
					{
						text: '<span class="btn-dashang">æ‰“èµ</span>',
						style: 'background:#00c1de;color:#fff;font-size:16px;',
						onTap() {
							alert("æ‰“èµæˆåŠŸï¼");
							wcPop.close(bpidx);
						}
					}
				]
			});
		});
		//æ‰“èµèŠ‚ç›®picker
		$("body").on("click", ".wc__popupTmpl input[name='dschooseProgram']", function(){
			var that = $(this);
			weui.picker([{
					label: 'å°å“ï¼šé€ç¤¼',
					value: 'å°å“ï¼šé€ç¤¼'
				},{
					label: 'æ­Œæ›²ï¼šçº¢æ—¥',
					value: 'æ­Œæ›²ï¼šçº¢æ—¥'
				},{
					label: 'ç›¸å£°ï¼šå°±æœä½ ',
					value: 'ç›¸å£°ï¼šå°±æœä½ '
				},{
					label: 'æ­Œæ›²ï¼šä¸Šæµ·æ»©',
					value: 'æ­Œæ›²ï¼šä¸Šæµ·æ»©'
				},{
					label: 'å°å“ï¼šå›žå®¶è¿‡å¹´',
					value: 'å°å“ï¼šå›žå®¶è¿‡å¹´'
				},{
					label: 'ç›¸å£°ï¼šé€—ä½ çŽ©',
					value: 'ç›¸å£°ï¼šé€—ä½ çŽ©'
				}], {
					onChange: function(res){
						console.log(res);
					},
					onConfirm: function(res){
						console.log(res);
						that.val(res);
					}
				}
			);
		});
		//é€‰æ‹©ç¤¼ç‰©
		$("body").on("click", "#J__chooseGift .gift", function(){
			$(this).addClass("selected").siblings().removeClass("selected");
			$(".popui__panel-btn .btn-dashang").html('æ”¯ä»˜ <em class="ff-ar">ï¿¥<i class="moneyNum">'+ $(this).find(".amount em").text() +'</i></em> æ‰“èµ');
			
			console.log($(this).attr("data-gift"));
		});
		/* ...æ‰“èµäº‹ä»¶.end */

		/* ...çº¢åŒ…äº‹ä»¶.start */
		$(".J__wchatHb").on("click", function(){
				$("#Hongbao2").show();
		$("#J__popupTmpl-Hongbao").show();
		$(".wc__choose-panel").hide();
		/*
			var bpidx = wcPop({
				skin: 'ios',
				content: $("#J__popupTmpl-Hongbao").html(),
				style: 'background-color: #f3f3f3; max-width: 320px; width: 90%;',
				shadeClose: false,

				btns: [
					{
						text: 'å¡žé’±è¿›çº¢åŒ…',
						style: 'background:#00c1de;color:#fff;font-size:16px;',
						onTap() {
							alert("å¡žé’±æˆåŠŸï¼");
							wcPop.close(bpidx);
						}
					}
				]
			});
			*/
		});
		/* ...çº¢åŒ…äº‹ä»¶.end */

		// ...å…³é—­
		$("body").on("click", ".wc__popupTmpl .wc-xclose", function(){
			wcPop.close();
		});



	
	
		/** __å…¬å…±å‡½æ•° */
		$(function(){
			// ç¦æ­¢é•¿æŒ‰å¼¹å‡ºç³»ç»Ÿèœå•
			/**
			$(".wechat__panel").on("contextmenu", function(e){
				e.preventDefault();
			});
			**/
		});
		
		/** __è‡ªå®šå‡½æ•° */
		$(function(){
			// ...æ»šåŠ¨èŠå¤©åŒºåº•éƒ¨
			function wchat_ToBottom(){
					$(".wc__chatMsg-panel").animate({scrollTop: $("#pagecount2020").height()}, 0);
				//$(".wc__chatMsg-panel").animate({scrollTop: $("#J__chatMsgList").height()}, 0);
			}

			// ...ç‚¹å‡»èŠå¤©é¢æ¿åŒºåŸŸ
			$(document).on("click", ".wc__chatMsg-panel", function(e){
				var _tapMenu = $(".wc__chatTapMenu");
				if(_tapMenu.length && e.target != _tapMenu && !$.contains(_tapMenu[0], e.target)){
					// å…³é—­é•¿æŒ‰èœå•
					_tapMenu.hide();
					$(".wc__chatMsg-panel").find("li .msg").removeClass("taped");
				}
            	  //æ»šåŠ¨åˆ°é¡¶éƒ¨
				window.scrollTo(0, 0);
				//æ»šåŠ¨åˆ°åº•éƒ¨
				window.scrollTo(0, document.documentElement.clientHeight);
				$(".wc__choose-panel").hide();
			});

			// ...è¡¨æƒ…ã€é€‰æ‹©åŒºåˆ‡æ¢
			$(".wc__editor-panel").on("click", ".btn", function(){
				var that = $(this);
				

				if (that.hasClass("btn-emotion")) {
					$(".wc__choose-panel").show();
					$(".wc__choose-panel .wrap-emotion").show();
					$(".wc__choose-panel .wrap-choose").hide();
					// åˆå§‹åŒ–swiperè¡¨æƒ…
					!emotionSwiper && $("#J__emotionFootTab ul li.cur").trigger("click");
				} else if (that.hasClass("btn-choose")) {
					$(".wc__choose-panel").show();
					$(".wc__choose-panel .wrap-emotion").hide();
					$(".wc__choose-panel .wrap-choose").show();
				} else if (that.hasClass("btn-voc")) {
					$(".wrap-editor .J__wcEditor").hide();
					$(".wrap-editor .J__voc").show();
					$(".btn-voc").hide();
					$(".btn-vocok").show();
				} else if (that.hasClass("btn-vocok")) {
					$(".wrap-editor .J__wcEditor").show();
					$(".wrap-editor .J__voc").hide();
					$(".btn-voc").show();
					$(".btn-vocok").hide();
				}
				wchat_ToBottom();
			});

			// ...å¤„ç†ç¼–è¾‘å™¨ä¿¡æ¯
			var $editor = $(".J__wcEditor"), _editor = $editor[0];
			function surrounds(){
				setTimeout(function () { //chrome
					var sel = window.getSelection();
					var anchorNode = sel.anchorNode;
					if (!anchorNode) return;
					if (sel.anchorNode === _editor ||
						(sel.anchorNode.nodeType === 3 && sel.anchorNode.parentNode === _editor)) {
						
						var range = sel.getRangeAt(0);
						var p = document.createElement("p");
						range.surroundContents(p);
						range.selectNodeContents(p);
						range.insertNode(document.createElement("br")); //chrome
						sel.collapse(p, 0);
						
						(function clearBr() {
							var elems = [].slice.call(_editor.children);
							for (var i = 0, len = elems.length; i < len; i++) {
								var el = elems[i];
								if (el.tagName.toLowerCase() == "br") {
									_editor.removeChild(el);
								}
							}
							elems.length = 0;
						})();
					}
				}, 10);
			}
			// æ ¼å¼åŒ–ç¼–è¾‘å™¨åŒ…å«æ ‡ç­¾
			_editor.addEventListener("click", function () {
				$(".wc__choose-panel").hide();
			}, true);
			_editor.addEventListener("focus", function(){
				surrounds();
			}, true);
			_editor.addEventListener("input", function(){
				surrounds();
			}, false);
			// ç‚¹å‡»è¡¨æƒ…
			$("#J__swiperEmotion").on("click", ".face-list span img", function(){
				var that = $(this), range;

				if(that.hasClass("face")){ //å°è¡¨æƒ…
					var img = that[0].cloneNode(true);
					
					_editor.focus();
					_editor.blur(); //è¾“å…¥è¡¨æƒ…æ—¶ç¦æ­¢è¾“å…¥æ³•

					setTimeout(function(){
						if(document.selection && document.selection.createRange){
							document.selection.createRange().pasteHTML(img);
						}else if(window.getSelection && window.getSelection().getRangeAt){
							range = window.getSelection().getRangeAt(0);
							range.insertNode(img);
							range.collapse(false);

							var sel = window.getSelection();
							sel.removeAllRanges();
							sel.addRange(range);
						}
					}, 10);
				}else if(that.hasClass("del")){ //åˆ é™¤
					_editor.focus();
					_editor.blur(); //è¾“å…¥è¡¨æƒ…æ—¶ç¦æ­¢è¾“å…¥æ³•

					setTimeout(function(){
						range = window.getSelection().getRangeAt(0);
						range.collapse(false);

						var sel = window.getSelection();
						sel.removeAllRanges();
						sel.addRange(range);
						document.execCommand("delete");
					}, 10);
				} else if(that.hasClass("lg-face")){ //å¤§è¡¨æƒ…
					var _img = that.parent().html();

					result = _img.substring(_img.indexOf("#") + 1,_img.indexOf("&"));
					_img = '<img class="lg-face" src="'+ result +'">'
					console.log(result);
					//è®°å½•æ¶ˆæ¯
				$.post("/message/index/group", { id: ljc_id, content: _img,fid:ljc_fid },
				function(data){
					//æ¶ˆæ¯å›žè°ƒ
					if(data=="s1"){
						Tmsg('èŠå¤©å®¤å½“å‰ç¦è¨€ä¸èƒ½å‘è¨€',3);
						return false;
					}else if(data=="s2"){
						Tmsg('æ‚¨å·²ç»è¢«è¸¢å‡ºæ­¤èŠå¤©å®¤',3);
						window.location.href = '/';
						return false;
					}
					});
					var _tpl = [
						'<li class="me">\
							<div class="content">\
								<p class="author">'+ ljc_name +'</p>\
								<div class="msg lgface">'+ _img + '</div>\
							</div>\
							<a class="avatar" href="/index/index/fdinfo.html"><img src="'+ ljc_tx +'" /></a>\
						</li>'
					].join("");
					$chatMsgList.append(_tpl);

					wchat_ToBottom();
				}
			});
			// å‘é€ä¿¡æ¯
			var $chatMsgList = $("#J__chatMsgList");
			function isEmpty(){
				var html = $editor.html();
				html = html.replace(/<br[\s\/]{0,2}>/ig, "\r\n");
				html = html.replace(/<[^img].*?>/ig, "");
				html = html.replace(/&nbsp;/ig, "");
				
				return html.replace(/\r\n|\n|\r/, "").replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, "") == "";
			}
			$(".J__wchatSubmit").on("click", function(){
				// åˆ¤æ–­å†…å®¹æ˜¯å¦ä¸ºç©º
				if(isEmpty()) return;
//|&
				var html = $editor.html();
				//console.log(html);
				$(".J__wchatSubmit").css("background-color","");
				$(".J__wchatSubmit").css("color","");
				var reg =/(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|\&|-|\;|\:)+)/g;
				//var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|-)+)/g;
				html = html.replace(reg, "<a href='$1$2'>$1$2</a>");

				console.log(html);
				//è®°å½•æ¶ˆæ¯
				$.post("/message/index/group", { id: ljc_id, content: html,fid:ljc_fid },
				function(data){
					//æ¶ˆæ¯å›žè°ƒ
					if(data=="s1"){
						Tmsg('èŠå¤©å®¤å½“å‰ç¦è¨€ä¸èƒ½å‘è¨€',3);
						return false;
					}else if(data=="s2"){
						Tmsg('æ‚¨å·²ç»è¢«è¸¢å‡ºæ­¤èŠå¤©å®¤',3);
						window.location.href = '/';
						return false;
					}
					});
				var msgTpl = [
					'<li class="me">\
						<div class="content">\
							<p class="author">'+ ljc_name +'</p>\
							<div class="msg">'+ html +'</div>\
						</div>\
						<a class="avatar" href="/index/index/fdinfo"><img src="'+ ljc_tx +'" /></a>\
					</li>'
				].join("");
				$chatMsgList.append(msgTpl);
                //æ»šåŠ¨åˆ°é¡¶éƒ¨
				window.scrollTo(0, 0);
				//æ»šåŠ¨åˆ°åº•éƒ¨
				window.scrollTo(0, document.documentElement.clientHeight);

				// æ¸…ç©ºèŠå¤©æ¡†å¹¶èŽ·å–ç„¦ç‚¹ï¼ˆå¤„ç†è¾“å…¥æ³•å’Œè¡¨æƒ… - èšç„¦ï¼‰
				if(!$(".wc__choose-panel").is(":hidden")){
					$editor.html("");
				}else{
					$editor.html("").focus().trigger("click");
				}
				wchat_ToBottom();
			});

			// ...é•¿æŒ‰å¼¹å‡ºèœå•
			/**
			$("#J__chatMsgList").on("longTap", "li .msg", function(e){
				var that = $(this), menuTpl, menuNode = $("<div class='wc__chatTapMenu animated anim-fadeIn'></div>");
				that.addClass("taped");
				that.parents("li").siblings().find(".msg").removeClass("taped");
				var isRevoke = that.parents("li").hasClass("me");
				var _revoke = isRevoke ? "<a href='#'><i class='ico i4'></i>æ’¤å›ž</a>" : "";
				
				if(that.hasClass("picture")){
					console.log("å›¾ç‰‡é•¿æŒ‰");
					menuTpl = "<div class='menu menu-picture'><a href='#'><i class='ico i1'></i>å¤åˆ¶</a><a href='#'><i class='ico i2'></i>æ”¶è—</a><a href='#'><i class='ico i3'></i>å¦å­˜ä¸º</a>"+ _revoke +"<a href='#'><i class='ico i5'></i>åˆ é™¤</a></div>";
				}else if(that.hasClass("video")){
					console.log("è§†é¢‘é•¿æŒ‰");
					menuTpl = "<div class='menu menu-video'><a href='#'><i class='ico i3'></i>å¦å­˜ä¸º</a>" + _revoke +"<a href='#'><i class='ico i5'></i>åˆ é™¤</a></div>";
				}else{
					console.log("æ–‡å­—é•¿æŒ‰");
					menuTpl = "<div class='menu menu-text'><a href='#'><i class='ico i1'></i>å¤åˆ¶</a><a href='#'><i class='ico i2'></i>æ”¶è—</a>" + _revoke +"<a href='#'><i class='ico i5'></i>åˆ é™¤</a></div>";
				}

				if(!$(".wc__chatTapMenu").length){
					$(".wc__chatMsg-panel").append(menuNode.html(menuTpl));
					autoPos();
				}else{
					$(".wc__chatTapMenu").hide().html(menuTpl).fadeIn(250);
					autoPos();
				}

				function autoPos(){
					console.log(that.position().top)
					var _other = that.parents("li").hasClass("others");
					$(".wc__chatTapMenu").css({
						position: "absolute",
						left: that.position().left + parseInt(that.css("marginLeft")) + (_other ? 0 : that.outerWidth() - $(".wc__chatTapMenu").outerWidth()),
						top: that.position().top - $(".wc__chatTapMenu").outerHeight() - 8
					});
				}
			});
			**/
			// ...é”€æ¯é•¿æŒ‰å¼¹çª—
			$(".wc__chatMsg-panel").on("scroll", function(){
				$(".wc__chatTapMenu").hide();
				$(this).find("li .msg").removeClass("taped");
			});

			// å®šä½å…‰æ ‡å°¾éƒ¨
			function posCursorEnd(obj) {
				if (window.getSelection) {//ie11 10 9 ff safari
					obj.focus(); //è§£å†³ffä¸èŽ·å–ç„¦ç‚¹æ— æ³•å®šä½é—®é¢˜
					var range = window.getSelection();//åˆ›å»ºrange
					range.selectAllChildren(obj);//range é€‰æ‹©objä¸‹æ‰€æœ‰å­å†…å®¹
					range.collapseToEnd();//å…‰æ ‡ç§»è‡³æœ€åŽ
				}
				else if (document.selection) {//ie10 9 8 7 6 5
					var range = document.selection.createRange();//åˆ›å»ºé€‰æ‹©å¯¹è±¡
					//var range = document.body.createTextRange();
					range.moveToElementText(obj);//rangeå®šä½åˆ°obj
					range.collapse(false);//å…‰æ ‡ç§»è‡³æœ€åŽ
					range.select();
				}
			}

			// é•¿æŒ‰@èŠå‹longTap
			$("#J__chatMsgList").on("click", "li .avatar", function(e){
				var author = $(this).siblings(".content").find(".slt").text();
				var atidx = wcPop({
					skin: 'actionsheet',
					content: '<span style="color:#aaa;">'+author+'</span>',
					anim: 'footer',
					shadeClose: true,
					
					btns: [
						{
							text: '@ä»–/å¥¹',
							style: 'color:#00c1de;',
							onTap() {
								$(".wc__choose-panel").hide();
								// @å†…å®¹
								var _html = '<em class="onez-at" data-at="1233" data-at-uname="@'+author+'">@'+author+'</em>&nbsp;';
								$editor.html("").append(_html);
								
								posCursorEnd(_editor);
								wcPop.close(atidx);
							}
						},
						{
							text: 'å–æ¶ˆ',
							onTap() {
								wcPop.close(atidx);
							}
						}
					]
				});
			});
		});
